package com.qi;

import java.util.Arrays;

/**
 * 希尔排序;先分组 然后在使用插入排序
 */
public class XiErPaiXu {

    public static void shellSort(int[] array) {
        for (int x = 0; x < 4; x++) {
            for (int y = x + 4; y < array.length; y = y + 4) {
                int insertValue = array[y];
                int j;
                for (j = y - 4; (j >= 0) && (insertValue < array[j]); j = j - 4) {
                    array[j + 4] = array[j];
                }
                array[j + 4] = insertValue;
            }
        }
    }

    public static void main(String[] args) {
        int[] ints = {5, 8, 6, 3, 9, 2, 1, 7};
        shellSort(ints);
        System.out.println(Arrays.toString(ints));
    }

}
